home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK2.toast / Development Kits (Disc 2) / ScriptX / Draggable ScriptX Folders / utils / widgets / smallte.sx < prev    next >
Encoding:
Text File  |  1995-11-13  |  1.9 KB  |  74 lines  |  [TEXT/ttxt]

  1. class SmallTextEdit ( TextEdit)
  2. class variables
  3.     defaultWidth:50
  4. instance variables
  5.     frame:(new Frame)
  6.     _font
  7. end
  8.  
  9. ------------------------
  10. -- parameters to init --
  11. -- brush: overrides the style's brush
  12. -- x,y:   position for the label
  13. -- width, height: use this size instead of calculating it from the text 
  14. -- text:  the text for the label
  15. method init self {class SmallTextEdit} #rest args #key    \
  16.             boundary:                                    \
  17.             font:(theSystemFont)                        \
  18.             text:myText("" as Text)                        \
  19.             fill:(WhiteBrush)                            \
  20.             ->
  21. (
  22.     
  23.     if (boundary = unsupplied) do
  24.         boundary := new Rect x2:SmallTextEdit.defaultWidth \
  25.             y2:(font.leading + 6)
  26.     -- bug in TextEdit requires text arg to be Text and not String
  27.     apply nextMethod self boundary:boundary target:(myText as Text)\
  28.         fill:fill stationary:true args
  29. )
  30.  
  31. method afterInit self {class SmallTextEdit} #rest args #key    \
  32.             font:(theSystemFont)                            \
  33.             inset:(new Point x:4 y:0)                        \
  34.              ->
  35. (
  36.     apply nextMethod self args
  37.     self.cursor := new Rect x2:2 y2:font.leading
  38.     self.font := font
  39.     self.inset := inset
  40.     self.selectionBackground := whiteBrush
  41. )
  42.  
  43. method fontGetter self {class SmallTextEdit} -> self._font
  44. method fontSetter self {class SmallTextEdit} newFont ->
  45. (
  46.     setDefaultAttr self @font newFont.font
  47.     setDefaultAttr self @size newFont.fontSize
  48.     setDefaultAttr self @leading newFont.leading
  49.     self.cursor := new Rect x1:-1 x2:0 \
  50.         y1:(-newFont.leading + newFont.descent) y2:0
  51.     self._font := newFont
  52. )
  53.  
  54. method recalcRegion self {class SmallTextEdit} ->
  55. (
  56.     nextMethod self
  57.     SetBoundary self.frame self.boundary
  58. )
  59.     
  60. method textSetter self {class SmallTextEdit} new_text ->
  61. (
  62.     self.target := if (isAKindOf new_text Text) then new_text
  63.         else (new_text as Text)
  64. )
  65.  
  66. method textGetter self {class SmallTextEdit} -> self.target
  67.  
  68. method draw self {class SmallTextEdit} surface clip -> 
  69. (
  70.     nextMethod self surface clip                    -- super (TextPresenter) draws the text
  71.     drawLoweredFrame self.frame surface clip self.globalTransform
  72. )
  73.  
  74.